package com.dt76.smallloanbackendservice.service.lhuaw.impl;

import com.dt76.smallloanbackendservice.mapper.lhuaw.StationLetterMapper;
import com.dt76.smallloanbackendservice.pojo.lhuaw.StationLetter;
import com.dt76.smallloanbackendservice.service.lhuaw.StationLetterService;
import com.dt76.smallloanbackendservice.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StationLetterServiceImpl implements StationLetterService {

    @Autowired
    private StationLetterMapper stationLetterMapper;

    @Override
    public List<StationLetter> qryAll() {
        return stationLetterMapper.qryAll();
    }

    @Override
    public Page getAllStationLetter(int pageIndex, String stationMessageTitle, String stationPublisher) {
       Page page =new Page();
       page.setPageIndex(pageIndex);
       page.setTotalCount(stationLetterMapper.qryConditionCount(stationMessageTitle,stationPublisher));
       List<StationLetter> stationLetterList = stationLetterMapper.getConditionPageAll((page.getPageIndex()-1)*page.getPageSize(),
               page.getPageSize(),stationMessageTitle,stationPublisher);
        System.out.println(stationLetterList);
       page.setRows(stationLetterList);
        return page;
    }

    @Override
    public void deleteStation(int stationId) {
        stationLetterMapper.deleteStation(stationId);
    }

    @Override
    public void addStation(StationLetter stationLetter) {
        stationLetterMapper.saveStation(stationLetter);
    }

    @Override
    public StationLetter seeStation(int stationId) {
        return stationLetterMapper.seeStation(stationId);
    }
}
